<extend name="Index/index"/>

<block name="box">
    <div class="view-product">
        <div class="info-center">
            <div class="manage-head">
                <h6 class="padding-left manage-head-con">{{$title}}</h6>
            </div>
        </div>
        <div class="layui-container" style="margin-top: 20px">
            <div class="layui-row">
                <form class="layui-form" method="post" action="{{:U('Goods/editDo')}}" id="myform">
                    <!--商品id-->
                    <input type="hidden" name="id" value="{{$goodsinfo.id}}">
                    <!--商品名称-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" required  lay-verify="required"  autocomplete="off" class="layui-input" value="{{$goodsinfo.name}}">
                        </div>
                    </div>
                    <!--商品类别-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品分类</label>
                        <div class="layui-input-block">
                            <select name="cate" lay-verify="required">
                                <foreach name="catelist" item="value">
                                    <if condition="$goodsinfo['category_id'] eq $value['id']">
                                        <option value="{{$value.id}}" selected> {{:str_repeat("----",substr_count($value['path'],","))}}>{{$value.name}}
                                        </option>
                                    <else/>
                                        <option value="{{$value.id}}">
                                            {{:str_repeat("----",substr_count($value['path'],","))}}>{{$value.name}}
                                        </option>
                                    </if>

                                </foreach>

                            </select>
                        </div>
                    </div>
                    <!--商品价格-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品价格</label>
                        <div class="layui-input-block">
                            <input type="number" name="price" required  lay-verify="required"  autocomplete="off" class="layui-input" value="{{$goodsinfo.price}}" id="price">
                        </div>
                    </div>
                    <!--库存-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">库存</label>
                        <div class="layui-input-block">
                            <input type="number" name="num" required  lay-verify="required"  autocomplete="off" class="layui-input" value="{{$goodsinfo.num}}" id="num">
                        </div>
                    </div>
                    <!--销售-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">销售</label>
                        <div class="layui-input-block">
                            <input type="number" name="sales_num" required  lay-verify="required"  autocomplete="off" class="layui-input" value="{{$goodsinfo.sales_num}}" readonly>
                        </div>
                    </div>
                    <!--上架-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">上架</label>
                        <div class="layui-input-block">
                            <input type="text" name="is_show"   autocomplete="off" class="layui-input" value="{{$goodsinfo.is_show}}"  id="is_show">
                        </div>
                    </div>
                    <!--热销-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">热销</label>
                        <div class="layui-input-block">
                            <input type="text" name="is_hot" required  lay-verify="required"  autocomplete="off" class="layui-input" value="{{$goodsinfo.is_hot}}" readonly id="is_hot">
                        </div>
                    </div>
                    <!--新品-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">新品</label>
                        <div class="layui-input-block">
                            <input type="text" name="is_new" required  lay-verify="required"  autocomplete="off" class="layui-input" value="{{$goodsinfo.is_new}}" readonly id="is_new">
                        </div>
                    </div>
                    <!--积分购买是否开启-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">积分购买</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_integral" value="0" title="不可以用积分购买" {{$goodsinfo['is_integral']== 0 ? "checked" : ""}} >
                            <input type="radio" name="is_integral" value="1" title="可以用积分购买"   {{$goodsinfo['is_integral'] == 1 ? "checked" : ""}}>
                        </div>
                    </div>
                    <!--积分数量-->
                    <div class="layui-form-item"  id="integral">
                        <label class="layui-form-label">积分数量</label>
                        <div class="layui-input-block">
                            <input type="number" name="integral_price" required  lay-verify="required"  autocomplete="off" class="layui-input" value="{{$goodsinfo.integral_price}}" id="integral_price">
                        </div>
                    </div>
                    <!--是否可以使用优惠券-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">优惠券</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_coupon" value="0" title="不可以用优惠券" {{$goodsinfo['is_coupon']== 0 ? "checked" : ""}} >
                            <input type="radio" name="is_coupon" value="1" title="可以用优惠券"   {{$goodsinfo['is_coupon'] == 1 ? "checked" : ""}}>
                        </div>
                    </div>

                    <!--是否参加主题-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">主题活动</label>
                        <div class="layui-input-block">
                            <input type="radio" name="special_id" value="0" title="没参加主题活动" {{$goodsinfo['special_id']== 0 ? "checked" : ""}} >
                            <input type="radio" name="special_id" value="1" title="已参加主题活动"   {{$goodsinfo['special_id'] == 1 ? "checked" : ""}}>
                        </div>
                    </div>
                    <!--是否参加秒杀-->
                    <!--<div class="layui-form-item">-->
                        <!--<label class="layui-form-label">秒杀活动</label>-->
                        <!--<div class="layui-input-block">-->
                            <!--<input type="radio" name="seckill_id" value="0" title="没参加秒杀活动" {{$goodsinfo['seckill_id']== 0 ? "checked" : ""}} >-->
                            <!--<input type="radio" name="seckill_id" value="1" title="已参加秒杀活动"   {{$goodsinfo['seckill_id'] == 1 ? "checked" : ""}}>-->
                        <!--</div>-->
                    <!--</div>-->

                    <!--商品类别-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品类别</label>
                        <div class="layui-input-block">
                            <input type="radio" name="goods_type" value="0" title="普通商品"{{$goodsinfo['goods_type']== 0 ? "checked" : ""}}>
                            <input type="radio" name="goods_type" value="1" title="秒杀商品" {{$goodsinfo['goods_type']== 1 ? "checked" : ""}}>
                            <input type="radio" name="goods_type" value="2" title="团购商品" {{$goodsinfo['goods_type']== 2 ? "checked" : ""}}>

                        </div>
                    </div>
                    <!--商品介绍-->
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">文本域</label>
                        <div class="layui-input-block">
                            <textarea name="msg" class="layui-textarea">{{$goodsinfo.msg}}</textarea>
                        </div>
                    </div>
                    <!--提交-->
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script>
        //Demo
        layui.use('form', function(){
            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function(data){
//                layer.msg(JSON.stringify(data.field));
                return true;
            });
        });

        //如果价格小于等于0 时,就不能提交
        $(function(){
            $("#myform").submit(function(){
                if($("#price").val() <= 0){
                    alert("价格不能小于等于0");
                    return false;
                }
                if($("#num").val() < 0){
                    alert("库存数量不能小于0");
                    return  false;
                }
                if($("#integral_price").val() < 0){
                    alert("积分数量不能小于0");
                    return  false;
                }
            })
        })
       load1();
        //上架 热销 新品 判断
        function load1(){
            var is_show = $("#is_show").val();
            var is_hot = $("#is_hot").val();
            var is_new = $("#is_new").val();

            if(is_show == 1){
                $("#is_show").val("已上架");
            }else{
                $("#is_show").val("已下架");
            }

            if(is_hot == 1){
                $("#is_hot").val("热销商品");
            }else{
                $("#is_hot").val("非热销商品");
            }

            if(is_new == 1){
                $("#is_new").val("新品");
            }else{
                $("#is_new").val("非新品");
            }
        }


    </script>
</block>